/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SourceCode;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;

/**
 *
 * @author ssaad
 */
public class Reservation implements Serializable
{


    private Member member;
    private Item item;
    private Date  ReservationDate;

    public Reservation(Member member, Item item, Date ReservationDate)
    {
        if(item.HaveCopy())
        {
            this.member = member;
            this.item = item;
            item.reservations.add(this);
            this.ReservationDate = ReservationDate;
        }
        else
        {
            System.out.println("Can't FReserve Item");
        }
        
    }

    public Date getReservationDate() {
        return ReservationDate;
    }

    public Item getItem() {
        return this.item;
    }

    public Member getMember() {
        return this.member;
    }



    public String tostring()
    {
        return "Member " + member.tostring() + " Reserve  Item:" + this.item.toString() + "on " + ReservationDate.toString();
    }

     /*
     *get first valid date of returned item which was reserved
     */
    public Date FirstValidDate()
    {
        ArrayList<Date> dates = item.Availableon();
        Collections.sort(dates);
        return dates.get(0);
    }

    public void RemoveReservation()
    {
        this.item.reservations.remove(this);
        this.member.reservations.remove(this);
    }


}
